package com.example.crossmall.service.impl;

import com.example.crossmall.mapper.UserMapper;
import com.example.crossmall.po.User;
import com.example.crossmall.po.UserExample;
import com.example.crossmall.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;
    @Override
    public User checkLogin(String username, String password) {
        UserExample example = new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andPasswordEqualTo(password);
        criteria.andUsernameEqualTo(username);
        return userMapper.selectByExample(example).get(0);
    }

    @Override
    public int create(User user) {
        return userMapper.insert(user);
    }

    @Override
    public List<User> findByUsername(String username) {
        UserExample example = new UserExample();
        example.createCriteria().andUsernameEqualTo(username);
        return userMapper.selectByExample(example);
    }

}
